#include <iostream>
#include "AltLRU.hpp"

using namespace std;

int main() {
	AltLRU<int> lru(5);

	//test1
	auto v1 = lru.get("nonexistent");
	cout << "Cache miss(NULL is ok): ";
	if( v1 == nullptr ) {
		cout << "(null)";
	}else{
		cout << *v1;
	}
	cout << endl;

	//test2
	lru.set("val", 123);
	auto v2 = lru.get("val");
	if(v2==nullptr) {
		cout << "Fail, go nULL\n";
	}else{
		cout << "Cache hit(must be 123): " << *v2 << endl;
	}
	lru.set("val", 123);
	v2 = lru.get("val");
	if(v2==nullptr) {
		cout << "Fail, go nULL\n";
	}else{
		cout << "Cache hit(must be 123): " << *v2 << endl;
	}

	//test3
	auto v3 = lru.getset("getset", []() -> int {
		cout << "Test3 lambda" << endl;
		return 4321;
	});
	cout << "Test3 (must be 4321 with lambda): " << *v3 << endl;
	v3 = lru.getset("getset", []() -> int {
		cout << "Test3 lambda" << endl;
		return 4321;
	});
	cout << "Test3 (must be 4321 without lambda): " << *v3 << endl;

	return 0;
}
